import Cookies from 'js-cookie'
import Config from '@/settings'

const TokenKey = Config.TokenKey

export function getToken() {
    return Cookies.get(TokenKey)
}

export function setUserInfo(userInfo) {
    let s = JSON.stringify(userInfo);
    return Cookies.set(Config.loginInfo, s);
}

export function getUserInfo() {
   let newVar = Cookies.get(Config.loginInfo);
   if(!newVar){
       return {idUsersinfo:1};
   }
   console.log(newVar);
   return JSON.parse(newVar);
}

export function setToken(token, rememberMe) {
    if (rememberMe) {
        return Cookies.set(TokenKey, token, {expires: Config.tokenCookieExpires})
    } else return Cookies.set(TokenKey, token)
}

export function removeToken() {
    Cookies.remove(Config.loginInfo);
    return Cookies.remove(TokenKey)
}
